<%@ page contentType="text/html; charset=utf-8" %>

<%@ include file="common.jsp" %>
<%@ page import="java.util.*" %>

<jsp:useBean id="cart" scope="session" class="mypack.ShoppingCart"/>

<html>
<head><title>BookCatalog</title>
<link href="CSS/style1.css" rel="stylesheet">
</head>
 <body>
<table width="100%" border="0">
  <tr>
    <td><center><table width="750" border="0" bgcolor="#FFFFFF">
      <tr>
        <td valign="top"><jsp:include page="banner.jsp"/></td>
      </tr>
      <tr>
        <td>
<%
  // Additions to the shopping cart
  String bookId = request.getParameter("Add");
  if (bookId != null) {
    BookDetails book = bookDB.getBookDetails(bookId);
    cart.add(bookId, book);
%>
<p><h3>
<font color="red">
您已将 </font><font color="#0000FF">《<i><%=book.getTitle()%></i> 》</font><font color="red">加入购物车</font></h3>
<%
}
if (cart.getNumberOfItems() > 0) {
%>

<p><strong><b><a href="<%=request.getContextPath()%>/showcart.jsp"><font size="+2">察看购物车</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="<%=request.getContextPath()%>/cashier.jsp"><font size="+2">付&nbsp;&nbsp;&nbsp;账</font></a></b></strong></p>

<%
}
%>

<h3>请选择想购买的书：</h3>
<center>
    <table width="100%" border="0">
  <tr>
    <td width="88%"><img src="Images/index_12.gif" width="161" height="46" /></td>
    <td width="12%"><img src="Images/reg.gif" width="84" height="54" /></td>
  </tr>
</table>
<table width="100%" border="0">
  <tr align="center" bgcolor="#CCCCCC">
    <td width="51%">书&nbsp;&nbsp;&nbsp;名</td>
    <td width="25%">作&nbsp;&nbsp;者</td>
    <td width="24%">购&nbsp;&nbsp;买</td>
  </tr>
</table><hr color="#00CC33" size="3"/>
    <table width="100%" border="0">
<%
  Collection c = bookDB.getBooks();
  Iterator i = c.iterator();
  while (i.hasNext()) {
    BookDetails book = (BookDetails)i.next();
    bookId = book.getBookid();
%>

<tr align="center" bgcolor="#ffffaa">
<td  width="51%" height="40" align="left">
<a href="<%=request.getContextPath()%>/bookdetails.jsp?bookId=<%=bookId%>"><strong>
<%=book.getTitle()%></strong></a></td>
<td  width="25%" height="40"><%=book.getName()%>
</td>
<td  width="24%" height="40">
<a href="<%=request.getContextPath()%>/catalog.jsp?Add=<%=bookId%>">加入购物车</a></td>

</tr>

<% } %>

</table></center>
</td>
      </tr>
      <tr>
        <td><jsp:include page="copyright.jsp"/></td>
      </tr>
    </table></center></td>
  </tr>
</table>

</body>
</html>
